home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / archivers / xfd / developer / sources / asm / xfdexehead.a < prev    next >
Text File  |  1999-06-14  |  4KB  |  195 lines

  1. * Objectheader
  2. *
  3. *    Name:        xfdExeHead.a
  4. *    Author:        SDI
  5. *    Version:    $VER: xfdExeHead.a 1.4 (23.02.1999) by SDI
  6. *    Distribution:    PD
  7. *    Description:    XFD external test header (program startup code)
  8. *    Compileropts:    -
  9. *    Linkeropts:    -
  10. *
  11. * 1.0   03.02.98 : first version
  12. * 1.1   04.02.98 : fixed a lot bugs
  13. * 1.2   09.08.98 : one little bug-fix
  14. * 1.3   09.12.98 : added ExecBase passing
  15. * 1.4   08.01.99 : added type output
  16. * 1.4   23.02.99 : added V39 autoallocation feature
  17.  
  18.         INCLUDE    "libraries/xfdmaster.i"
  19.         INCLUDE    "exec/memory.i"
  20.         INCLUDE    "dos/dos.i"
  21.  
  22.         MOVEA.L    A0,A5
  23.         MOVE.L    D0,D7            * store them
  24.  
  25.         * get dos library opened
  26.         MOVEQ    #33,D0
  27.         MOVEA.L    4.W,A6
  28.         LEA.L    DosName(PC),A1
  29.         JSR    _LVOOpenLibrary(A6)
  30.         TST.L    D0
  31.         BEQ.W    .NoDos
  32.         MOVEA.L    D0,A4            * A4 is DosBase
  33.  
  34.         * open source file
  35.         MOVEA.L    A4,A6
  36.         CLR.B    -1(A5,D7)        * clear return
  37.         MOVE.L    A5,D1
  38.         MOVE.L    #MODE_OLDFILE,D2
  39.         JSR    _LVOOpen(A6)
  40.         MOVE.L    D0,D6            * D6 is InFH
  41.         BEQ.W    .NoFH
  42.         MOVE.B    #'D',-1(A5,D7)        * create save name
  43.         CLR.B    (A5,D7)
  44.  
  45.         * seek to end and back to start --> get file size
  46.         MOVE.L    D6,D1
  47.         MOVEQ    #0,D2
  48.         MOVEQ    #OFFSET_END,D3
  49.         JSR    _LVOSeek(A6)
  50.         MOVE.L    D6,D1
  51.         MOVEQ    #0,D2
  52.         MOVEQ    #OFFSET_BEGINNING,D3
  53.         JSR    _LVOSeek(A6)
  54.         MOVEA.L    A6,A4
  55.         MOVE.L    D0,SourceSize
  56.  
  57.         * allocate memory
  58.         MOVEA.L    4.W,A6
  59.         MOVEQ.L    #MEMF_ANY,D1
  60.         JSR    _LVOAllocMem(A6)
  61.         MOVEA.L    A4,A6
  62.         MOVE.L    D0,SourceBuf
  63.         BEQ.W    .NoSourceBuf
  64.  
  65.         * read in buffer
  66.         MOVE.L    D6,D1
  67.         MOVE.L    D0,D2
  68.         MOVE.L    SourceSize(PC),D3
  69.         JSR    _LVORead(A6)
  70.         CMP.L    #-1,D0
  71.         BEQ.W    .noread
  72.  
  73.         * call recog functions
  74.         LEA.L    ForeMan(PC),A2
  75.         MOVEA.L    xfdf_FirstSlave(A2),A2
  76. .recogloop    MOVE.L    A2,D0                * for test purpose
  77.         BEQ.W    .notfound
  78.         MOVE.L    SourceSize(PC),D0
  79.         MOVEA.L    SourceBuf(PC),A0
  80.         LEA    xfdrr(PC),A1
  81.         MOVEA.L    xfds_RecogBuffer(A2),A3
  82.         JSR    (A3)
  83.         TST.L    D0
  84.         BNE.B    .found
  85.         MOVEA.L    xfds_Next(A2),A2
  86.         BRA.B    .recogloop
  87. .found        * call decrunch function
  88.         LEA    FormatStr(PC),A0
  89.         MOVE.L    A0,D1
  90.         LEA    xfds_PackerName(A2),A0
  91.         MOVE.L    A0,D2
  92.         JSR    _LVOVPrintf(A6)
  93.  
  94.         MOVE.W    xfds_PackerFlags(A2),D0
  95.         AND.W    #XFDPFF_USERTARGET,D0
  96.         BEQ.B    .CallDecr
  97.  
  98.         MOVEQ    #-1,D0                * no allocation possible
  99.         CMP.L    MinTargetLen(PC),D0
  100.         BEQ.B    .CallDecr
  101.  
  102.         MOVE.L    MinTargetLen(PC),D0
  103.         CLR.L    D1
  104.         MOVE.L    4.W,A6
  105.         JSR    _LVOAllocMem(A6)
  106.         MOVE.L    D0,UserBuf
  107.         BEQ.W    .notfound
  108.         MOVE.L    D0,TarBuf
  109.  
  110.         MOVE.W    #XFDFF_USERTARGET|XFDFF_MASTERALLOC,Flags
  111.         MOVE.L    MinTargetLen(PC),UserBufLen
  112.         MOVE.L    MinTargetLen(PC),TarLen
  113.         MOVE.L    FinalTargetLen(PC),TarSaveLen
  114.  
  115. .CallDecr    LEA    xfdbi(PC),A0
  116.         MOVEA.L    xfds_DecrunchBuffer(A2),A3
  117.         MOVE.L    4.W,-(A7)
  118.         LEA    -$3A(A7),A6        * create ExeBase ptr
  119.  
  120.         NOP
  121.         NOP    * for easier detection of jumpin in Debugger
  122.         NOP
  123.         NOP
  124.  
  125.         JSR    (A3)
  126.         MOVE.L    (A7)+,A6        * correct stack
  127.         TST.L    D0
  128.         BEQ.B    .notfound
  129.  
  130.         * open destination file
  131.         MOVEA.L    A4,A6
  132.         MOVE.L    A5,D1
  133.         MOVE.L    #MODE_NEWFILE,D2
  134.         JSR    _LVOOpen(A6)
  135.         MOVE.L    D0,D5            * D5 is OutFH
  136.         BEQ.B    .NoOutFH
  137.  
  138.         * write destination
  139.         MOVE.L    D5,D1
  140.         MOVE.L    TarBuf(PC),D2
  141.         MOVE.L    TarSaveLen(PC),D3
  142.         JSR    _LVOWrite(A6)
  143.  
  144.         * close destination
  145.         MOVE.L    D5,D1
  146.         JSR    _LVOClose(A6)
  147. .NoOutFH    MOVEA.L    4.W,A6            * free decrunch buffer
  148.         MOVE.L    TarLen(PC),D0
  149.         MOVEA.L    TarBuf(PC),A1
  150.         JSR    _LVOFreeMem(A6)
  151.         CLR.W    Flags
  152. .notfound    TST.W    Flags            * free own buffer when error
  153.         BEQ.B    .noread            * occured
  154.         MOVE.L    UserBufLen(PC),D0
  155.         MOVEA.L    UserBuf(PC),A1
  156.         JSR    _LVOFreeMem(A6)
  157. .noread        MOVEA.L    4.W,A6            * free source buffer
  158.         MOVEA.L    SourceBuf(PC),A1
  159.         MOVE.L    SourceSize(PC),D0
  160.         JSR    _LVOFreeMem(A6)
  161. .NoSourceBuf    MOVEA.L    A4,A6            * close input fh
  162.         MOVEA.L    D6,D1
  163.         JSR    _LVOClose(A6)
  164. .NoFH        MOVEA.L    A4,A1            * close dos
  165.         MOVEA.L    4.W,A6
  166.         JSR    _LVOCloseLibrary(A6)
  167. .NoDos        RTS
  168.  
  169. xfdbi
  170. SourceBuf    DC.L    0
  171. SourceSize    DC.L    0
  172.         DC.L    0
  173.         DC.L    0
  174.         DC.W    XFDPFF_RELOC,XFDERR_OK
  175. TarBuf        DC.L    0
  176.         DC.L    MEMF_ANY
  177. TarLen        DC.L    0
  178. TarSaveLen    DC.L    0
  179.         DC.L    0,0,0
  180. Flags        DC.W    0
  181.         DC.W    0
  182.         DC.L    0,0
  183. UserBuf        DC.L    0
  184. UserBufLen    DC.L    0
  185.         DC.L    0    * MinSourceLen
  186.  
  187. xfdrr
  188. MinTargetLen    DC.L    0
  189. FinalTargetLen    DC.L    0
  190.         DC.L    0
  191. DosName     DC.B    "dos.library",0
  192. FormatStr    DC.B    'Cruncher-Name: %s\n',0
  193.         EVEN
  194.  
  195.